// pages/dataset/dataset.js
var userService = require('../../services/userService.js');
var app = getApp()
var util = require('../../utils/util.js');
var commonService = require('../../services/commonService.js');
var city = require('../../utils/city.js');
var activityService = require('../../services/activityService.js');
Page({
  data:{
    formData:{},
    f_click:false,
    now_city:'',
    now_city_id:''
  },
   clickReturn:function(e){
    wx.navigateBack();
  },
  onLoad:function(options){
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数
    wx.showModal({
      title: '提示',
      content: '请认真填写身份资料,并确保填写的资料准确,中华志愿者协会将审核用户的实名资料,如果资料审核出错,用户账号将被锁定,请知悉,谢谢!',
      showCancel:false,
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    });
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
    var that = this;

    that.getSelfInfo();
  
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  formSubmit:function(e){
    var that = this;
    that.data.formData = e.detail.value
    that.data.formData.success=function(res){
      that.setData({
        f_click: true
      })
      wx.showToast({
        title: '设置成功',
      },2000)
      setTimeout(function(){
        wx.switchTab({
          url: '../myself/myself',
        })
      },1800)
    }
    userService.setSelfInfo(that.data.formData)
  },
  getSelfInfo:function(){
    var that = this;
    userService.getSelfInfo({
      user_id: app.globalData.apiUser,
      success:function(res){
        that.setData({
          userInfo:res
        })
      }
    })
  },
  choosecity:function(e){
    wx.navigateTo({
      url: './chooseCity?city=' + e.currentTarget.dataset.now_city + '&city_id=' + e.currentTarget.dataset.now_city_id,
    })
  },
  backTopPrevNavigate: function () {
    wx.navigateBack()
  }
})